package com.example.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;


/**
 * Created with IntelliJ IDEA.
 * ClassName: HBaseConnection
 * Package: com.example.hbase
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-08-03
 * Time: 20:55
 */

public class HBaseConnection {

    //单线程创建连接
    public static void main(String[] args) throws IOException {

        //创建配置
        Configuration conf = new Configuration();

        //添加配置参数 放键值对
        //hbase是有zookeeper实现分布式的 在配置文件中
        conf.set("hbase.zookeeper.quorum","hadoop102,hadoop103,hadoop104");

        //创建连接
        //默认使用同步连接
        Connection connection = ConnectionFactory.createConnection(conf);

        //可以使用异步连接
        //CompletableFuture<AsyncConnection> asyncConnection = ConnectionFactory.createAsyncConnection(conf);

        //4.使用连接
        System.out.println(connection);

        //5.关闭连接
        connection.close();
    }

}
